<? /* license

BilugCMS (http://www.bilug.it) - Content Management System for dynamic web sites
Copyright (C) 2005-2008  Federico Villa and Alessio Loro Piana

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

For reference, contact bilugcms@vilnet.it


license */ ?>
<h3>Lista Files</h3>
<?
require_once("auth.php");
require_once("../utility/funzioni.php");
$dir = apici($_GET['dir']);
$titolo = apici($_GET['titolo']);
If (isset($_GET['g'])) $g=1;
else $g=0;
?>
<script type="text/javascript">
$(function() {
	 $('#lista li > ul').each(function(i) {
    	  var parent_li = $(this).parent('li');
        parent_li.addClass('folder');
        var sub_ul = $(this).remove();
        parent_li.wrapInner("<a/>").find('a').click(function() {
        		sub_ul.toggle();        		
        });
        parent_li.append(sub_ul);
        $('#lista a').not(".del").fancyzoom({Speed:1000,showoverlay:true,overlay:7/10});        
    });
    $('#lista ul ul').hide();
});
</script>
<style>
#lista ul {
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 10pt;
}
#lista li {
    background-image: none;
    background-position: 0 1px;
    background-repeat: no-repeat;
    padding-left: 20px;
}
#lista li.folder {
    background-image: url(../img/folder.png);
}

#lista a {
    color: #000000;
    cursor: pointer;
    text-decoration: none;
}
#lista a:hover {
    text-decoration: underline;
}

</style>
<?
echo "<div class=\"contenitore\">";
if ($g==1) echo "<a href=\"javascript:history.go(-1)\">Ritorna</a><br/>";
echo "<div id=\"lista\">";
$extension = array(".jpg",".jpeg",".gif",".png");
echo "<h5>$titolo</h5><br/>";
function tree( $dir ,$g=0)
{  
	$nofile = true; //segnala se non sono stati trovati file sotto una directory
	if( is_dir( $dir ) )
	{
		$lista .= "<ul>";
      foreach( scandir( $dir) as $item )
		{
			if( !strcmp( $item, '.' ) || !strcmp( $item, '..' ) || !strcmp( $item, 'index.php' )|| !strcmp( $item, '.htaccess' ) )
         continue;                
         if(is_dir($dir."/".$item)==TRUE)
         {
         	if ($g==1) // In caso si stia visualizzando una galleria visualizza il nome senza i controlli di ordine
         		$lista .= "<li><span> Directory:	".str_replace("_"," ",substr($item,strpos($item,"_")+1))."</span>";
         	else
         		$lista .= "<li><span> Directory: $item</span>";              
           	$lista .= tree( $dir. "/" . $item,$g);
         	$lista .= "</li>";    
         	$nofile = false;     	 
         }
         else
         {
         	$nofile = false;
         	if (in_array(substr($item,strpos($item,".")),array(".jpg",".jpeg",".gif",".png")))
         	{
         	$lista .= "<li><a class=\"del\" href=\"del.php?what=$dir/$item\">\n
         				<img border=\"0\" src=\"./img/elimina.gif\" \></a>
         				<a href=\"$dir/$item\">\n
           				<img valign=\"middle\" src=\"../utility/thump.php?w=30&amp;h=30&amp;file=$dir/$item&amp;nowa=1\"/> $item</a>
         			</li>";
         	}
         	else
         	{
         	$lista .= "<li><a class=\"del\" href=\"del.php?what=$dir/$item\">\n
         				<img border=\"0\" src=\"./img/elimina.gif\" \></a>
         				<a href=\"$dir/$item\">\n
           				 $item</a>
         			</li>";
         	}
         	
      	}      	
   	}
   	if ($nofile == true) $lista .="<li>Nessun File presente</li>";
   	$lista .= "</ul>";
   	return $lista;
   } 
   
}
$lista = tree ($dir,$g);
echo $lista;
echo "</div>";
if ($g==1) echo "<a href=\"javascript:history.go(-1)\">Ritorna</a><br/>";
echo "</div>";
?>  
